package coder.nav.enums;

import coder.nav.model.vo.NavKeyValueVO;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * 消费类型
 */
@Getter
@AllArgsConstructor
public enum NavCashTypeEnums {

    OTHER(0, "🏦", "其他"),
    FOOD(1, "🍹", "饮食"),
    SHOP(2, "🛍️", "购物"),
    PHONE(3, "☎️", "通讯"),
    SHIP(4, "🚌", "通勤"),
    GAME(5, "✈️", "游玩"),
    HOUSE(6, "🏘️", "房租"),
    SALARY(7, "💵", "薪资"),
    ;
    private final Integer key;
    private final String icon;
    private final String value;

    public static List<NavKeyValueVO<Integer, String>> getList() {
        List<NavKeyValueVO<Integer, String>> list = new ArrayList<>();
        NavCashTypeEnums[] es = NavCashTypeEnums.values();
        NavKeyValueVO<Integer, String> other = null;
        for(NavCashTypeEnums e : es) {
            NavKeyValueVO<Integer, String> vo = new NavKeyValueVO<>();
            vo.setKey(e.getKey());
            vo.setValue(e.getIcon() + " " +e.getValue());
            if(e == NavCashTypeEnums.OTHER) {
                other = vo;
            } else {
                list.add(vo);
            }
        }
        list.add(other);
        return list;
    }

    public static NavCashTypeEnums getByKey(Integer key) {
        NavCashTypeEnums[] es = NavCashTypeEnums.values();
        for(NavCashTypeEnums e : es) {
            if(Objects.equals(e.getKey(), key)) {
                return e;
            }
        }
        return null;
    }

    public static String getValueByKey(Integer key) {
        NavCashTypeEnums e = getByKey(key);
        return Objects.nonNull(e) ? e.getValue() : "";
    }

    public static String getIconByKey(Integer key) {
        NavCashTypeEnums e = getByKey(key);
        return Objects.nonNull(e) ? e.getIcon() : "";
    }

}
